module ApplicationHelper

  def active_if(options)
    'bold active' if options.all?{|k,v|params[k].to_s.underscore==v.to_s.underscore}
  end
  
  def active_if_not(options)
    'blod active' unless options.all?{|k,v|v.include?(params[k].to_s.underscore)}
  end

  def grid_operator(path, id, do_show, do_edit, do_delete)  
    show, edit, delete = '', '', ''  
    show = link_to send(path, id), class: [:btn, 'btn-xs', 'btn-primary'], title: "明细" do  
      raw "<i class='glyphicon glyphicon-th-list'></i>"  
    end if do_show  
    edit = link_to send("edit_#{path.to_s}", id), class: [:btn, 'btn-xs', 'btn-success'], title: "修改" do  
      raw "<i class='glyphicon glyphicon-edit'></i>"  
    end if do_edit  
    delete = link_to send(path, id), data: {confirm: '一旦删除,将无法恢复,是否删除?'}, method: :delete, title: "删除",class: [:btn, 'btn-xs', 'btn-danger'] do  
      raw "<i class='glyphicon glyphicon-trash'></i>"  
    end if do_delete  
  
    return raw(show+" "+edit+" "+delete)  
  end  

  def grid_pay(path, id, payment_status)
    pay, back = '', ''
    pay = link_to send("finance_#{path.to_s}_pay_path", :id=>id), :remote=>true, class: [:btn, 'btn-xs', 'btn-primary', 'a'], title: "结算" do  
      raw '结算' 
    end if payment_status == "未付款"
    back = link_to send("finance_#{path.to_s}_path", :back=>id), class: [:btn, 'btn-xs', 'btn-warning'], title: "反结算" do  
      raw '反结算'
    end if payment_status == "已付款" 

    return raw(pay+" "+back)  
  end
end
